//
// Created by gogoqiu on 2022/1/12.
//

#ifndef RAPIDSVN_CMAKE_FUNC_H
#define RAPIDSVN_CMAKE_FUNC_H

/*
#define MY_SQL_HOST "git.my.host"
#define MY_SQL_USER "gogoqiu"
#define MY_SQL_PASS "512512ZoPoqiu"
#define MY_SQL_DB "clientV1"
#define MY_SQL_PORT 3306
*/

struct Item {
    //a15050d8-185d-11eb-9d28-34e12d834659
    wxString uuid;
    wxString name;
    //wxULongLongNative size;
    unsigned long long size;
    //
    wxString md5;
    wxString md4;
    unsigned long long lastModified;
    wxString mime;
    wxString path;
    int accessType;
    int fileType;
    long recordTime;
    wxString content;
    wxString tags;
};

int gen_uuid( char* buf );

wxString gen_uuid_string();

//file log
//

//int scpRep( wxWindow *parent, wxFileName localFile, wxString uuid, char* md5sum );
//int record();
class RepSession{
private:
    Item *item;
    wxFileName fileName;
    wxWindow *parent;
    wxFile *logFile;

    MYSQL *conn_ptr;
    bool should_delete_file;

    wxString buildSql();
    int scpRep(  );
    int realScp( wxWindow *parent, const wxFileName& localFile,
                 const wxString& uuid, char* md5sum, char* md4sum );
    int record(  );
    int reconnect();

    void addLog( const wxString& log );
    void addMySqlLog( wxString log );
public:
    void init( wxFileName fileName, wxWindow *parent,
            MYSQL *conn_ptr, bool should_delete_file );
    void postFile();
    ~RepSession();
};

#endif //RAPIDSVN_CMAKE_FUNC_H
